<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="title"
    :visible.sync="openTransfer"
    @close="handleClose"
    width="400px"
    append-to-body
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="变更负责人" prop="userId">
        <el-select v-model="form.userId" placeholder="请选择员工" filterable>
          <el-option
            v-for="owner in options"
            :key="owner.userId"
            :label="owner.userName"
            :value="owner.userId"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="handleClose">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { transferCrmCustomer } from "@/api/crm/customer";

export default {
  name: "TransferCustomerComponent",
  data() {
    return {
      // 弹出层标题
      title: "转移",
      // 是否显示弹出层
      openTransfer: false,
      ownerList: undefined,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [{ required: true, message: "请选择员工", trigger: "change" }],
      },
    };
  },
  props: {
    options: {
      type: Array,
      default: [],
    },
  },
  created() {},
  methods: {
    open(id) {
      this.form.customerId = id;
      this.openTransfer = true;
    },
    handleClose() {
      this.form = {
        ids: undefined,
        owner: undefined,
      };
      this.openTransfer = false;
      this.$emit("closeDialog");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          transferCrmCustomer(this.form).then((response) => {
            this.$modal.msgSuccess("转移成功");
            this.handleClose();
          });
        }
      });
    },
  },
};
</script>
